function Add-PartialBranch {
<#
.SYNOPSIS
Creates a TFS partial branch based on mappings from an existing branch

.DESCRIPTION
A local workspace is created that takes the mappings passed in and replaces the ServerPathToBranch argument with the PartialBranchPath. A Branch operation is then performed to branch ServerPathToBranch to PartialBranchPath and then the new branch is commited. If the Partial branch already exists, the branch operation will not be included.

.PARAMETER Mappings
List of mappings from the parent branch workspace to include in partial branch.

.PARAMETER TfsUrl
The TFS Collection URL to use for connecting to TFS

.PARAMETER LocalSourcePath
Local path where the workspace mappings should be rooted to

.PARAMETER ServerPathToBranch
Server path of the TFS directory being branched

.PARAMETER PartialBranchPath
Server path of destination branch

.PARAMETER LocalPathToken
String in the local path of the Mappings to be replaced with the LocalSourcePath parameter. The default is 'c:\'.

.PARAMETER Force
If a wokspace already exists that was not created by BigGit then add these mappings to that workspace

.EXAMPLE
Invoke-TF workfold /workspace:"SomeOtherWorkspace;Matt Wrock" | Add-PartialBranch -tfsUrl http://myserver:8080/tfs -localSourcePath "c:\dev\src\" -localPathToken "c:\" -ServerPathToBranch $/my/branch -PartialBranchPath $/my/new/branch

This will create a new workspace at c:\dev\src and branch $/my/path to $/my/new/path

.LINK
https://BigGit.Codeplex.com
#>    
    param(
        [Parameter(position=0,Mandatory=$True,ValueFromPipeline=$True)]
        [string[]] $mappings,
        [Parameter(Mandatory=$true)]
        [string] $tfsUrl, 
        [Parameter(Mandatory=$true)]
        [string] $localSourcePath, 
        [Parameter(Mandatory=$true)]
        [string] $serverPathToBranch, 
        [Parameter(Mandatory=$true)]
        [string] $partialBranchPath, 
        [string] $localPathToken = 'c:\',
        [switch] $force
    )
    begin {
        Write-BigGitMessage "Creating enlistment of $serverPathToBranch branching to $partialBranchPath at $localSourcePath"  -backgroundColor darkgreen
        $pipedMappings = @()
    }
    process { 
        foreach($map in $mappings){
            $pipedMappings += $map
        }
    }
    end {
        $currentDirectory = resolve-path .
        try {
            Invoke-TF dir $partialBranchPath /collection:$tfsUrl | out-null
            if($LastExitCode -eq 0) {
                $branchExists = $true
            }
            if(Add-Workspace $pipedMappings -tfsUrl $tfsUrl -localSourcePath $localSourcePath -branch $partialBranchPath -branchToken $serverPathToBranch -localPathToken $localPathToken -force:$force){
                Set-Location "$localSourcePath"
                Set-BigGitConfig "PartialPath" (resolve-path .).Path
                Set-BigGitConfig "SourceBranch" $serverPathToBranch
                Set-BigGitConfig "PartialBranch" $partialBranchPath
                if(!$branchExists)
                {
                    Write-BigGitMessage "Creating partial branch of $serverPathToBranch to $partialBranchPath"  -backgroundColor darkgreen
                    Invoke-TF branch $serverPathToBranch $partialBranchPath /noprompt
                    if($LastExitCode -gt 0) {
                        throw "unable to branch to $partialBranchPath"
                    }
                    Write-BigGitMessage "Checking in $partialBranchPath"  -backgroundColor darkgreen
                    Invoke-TF checkin /comment:"branching $serverPathToBranch" /noprompt
                    if($LastExitCode -gt 0) {
                        throw "unable to branch to $partialBranchPath"
                    }
                }
                Set-NonVolatileLinks
            }
        } finally {Set-Location $currentDirectory}
    }
}